# from ldap_lib import *
from function_lib import *
from ad_manage_views import new_ldap

guest_views = Blueprint('guest_views', __name__)


@guest_views.route('/register', methods=DEFAULT_METHODS)
def register():
    """

    :return: 无需返回任何信息
    """

    return render_template('register.html')


@guest_views.route('/add_user_self_service', methods=API_METHODS)
def add_user_self_service():
    try:
        username = request.form.get('username')
        password = request.form.get('password')
        dn = new_ldap.self_service_dc.split(',')
        dic = {'name': username, 'user_passwrod': password, 'dn': dn}
        msg = new_ldap.create_user(**dic)
        data = {'code': 1, 'msg': msg}
    except Exception as e:
        data = {'code': 2, 'msg': e}
    return data
